
package com.songbl.bless.app.controller;


import com.songbl.bless.app.entity.BlessInfo;
import com.songbl.bless.app.entity.UserEntity;
import com.songbl.bless.app.form.LoginForm;
import com.songbl.bless.app.service.BlessInfoService;
import com.songbl.bless.app.service.UserService;
import com.songbl.bless.app.util.JwtUtils;
import com.songbl.bless.common.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 测试使用：Postman
 *   URL： http://localhost:8080/rest-boot/app/login
 *   Header：content-type：application/json;chartset=utf-8
 *   Body: {
 * 	          "mobile": "13336371247",
 *             "password": "123456"
 *         }
 *
 * APP登录授权
 *
 * 791243928@qq.com
 * 1.@RestController注解：由下面两个注解构成
 *      @Controller
 *      @ResponseBody  //自动将数据（map或者对象）转换为JSON格式
 * 2. @RequestBody ：  将请求的json转化为对象 （通过jackson）
 *
 */
@RestController
@RequestMapping("/app")
public class BlessInfoController {
    private static Logger logger = LoggerFactory.getLogger(BlessInfoController.class);

    @Autowired(required = false)
    private BlessInfoService blessInfoService;

    /**
     * 获取消息
     */
    @PostMapping("addBlessInfo")
    public R addBlessInfo(@RequestBody BlessInfo blessInfo){
        System.out.println("短线消息 "+blessInfo.toString());
        Boolean aBoolean = blessInfoService.addBlessInfo(blessInfo);
        Map<String, Object> map = new HashMap<>();
        map.put("result",aBoolean);
        return R.ok(map);
    }


    /**
     * 获取所有祝福
     */
    @PostMapping("getBlessInfos")
    public R getBlessInfo(@RequestBody BlessInfo blessInfo){
        System.out.println("短线消息 "+blessInfo.toString());
        List<BlessInfo> blessInfos = blessInfoService.getBlessInfos(blessInfo.getUserId());
        Map<String, Object> map = new HashMap<>();
        map.put("result",blessInfos);
        return R.ok(map);
    }
}
